using Digitalmes.Domain.Entities.Mes.Masters;

namespace Digitalmes.Application.Mes.Masters.Workshops.Queries;

/// <summary>
/// 生产车间分页查询命令。
/// </summary>
public record GetWorkshopListWithPagedQuery(
    int PageNumber,
    int PageSize) : IPagedQuery, IRequest<IResult<PagedList<MdWorkshopDto>>>;

internal sealed class GetWorkshopListWithPagedQueryHandler(IRepository<MdWorkshop> repo) : IRequestHandler<GetWorkshopListWithPagedQuery, IResult<PagedList<MdWorkshopDto>>>
{
    public async Task<IResult<PagedList<MdWorkshopDto>>> Handle(GetWorkshopListWithPagedQuery request, CancellationToken cancellationToken)
    {
        var items = await repo.GetPagedListAsync(request.PageNumber, request.PageSize, cancellationToken);
        return Result.From(items.Adapt<PagedList<MdWorkshopDto>>());
    }
}
